package com.mcm.dao;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.mcm.dto.ProductoVenta;
import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;

public class VentasDao
{
	public void guardarVenta(ProductoVenta pv)
	{
		DBCollection ventas = MongoConnection.getVentasCollection();
		DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
		
		BasicDBObject doc = new BasicDBObject("nombre", pv.getDescripcion()).
				append("precioVenta", pv.getPrecioVenta()).
				append("cantidad", pv.getCantidad()).
				append("fecha", df.format(new Date())).
				append("nroVenta", getNumeroVenta());
		ventas.insert(doc);
	}
	
	private int getNumeroVenta()
	{
		DBCollection ventas = MongoConnection.getNroVentaCollection();
		DBObject object = ventas.findOne();
		
		Integer nroVenta = (Integer)object.get("nroVenta");
		return nroVenta;
	}
}
